﻿#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QMetaObject>
#include "Source/Controller/Tools/systemcheck.h"
#include <QTextCodec>

int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/Qml/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);


//    SYSTEM_INFO systemInfo;
//    GetSystemInfo(&systemInfo);
//    qDebug() << QStringLiteral("处理器掩码:") << systemInfo.dwActiveProcessorMask;
//    qDebug() << QStringLiteral("处理器个数:") << systemInfo.dwNumberOfProcessors;
//    qDebug() << QStringLiteral("处理器分页大小:") << systemInfo.dwPageSize;
//    qDebug() << QStringLiteral("处理器类型:") << systemInfo.dwProcessorType;
//    qDebug() << QStringLiteral("最大寻址单元:") << systemInfo.lpMaximumApplicationAddress;
//    qDebug() << QStringLiteral("最小寻址单元:") << systemInfo.lpMinimumApplicationAddress;
//    qDebug() << QStringLiteral("处理器等级:") << systemInfo.wProcessorLevel;
//    qDebug() << QStringLiteral("处理器版本:") << systemInfo.wProcessorRevision;


    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));


    QList<QObject *> root=engine.rootObjects();
    auto InfoText=root.first()->findChild<QObject *>("InfoText");

    //用来接收返回值的变量
    QVariant ret;
    //调用Qml内的函数。Q_RETURN_ARG()接收返回值，Q_ARG()传入参数
    //QMetaObject::invokeMethod(InfoText,"setText",Q_RETURN_ARG(QVariant,ret),Q_ARG(QVariant,"系统环境检测中..."));
    QMetaObject::invokeMethod(InfoText,"setText",Q_ARG(QVariant,"系统环境检测中..."));
    QString a="位";
    if (SystemCheck::CheckSystem())
        QMetaObject::invokeMethod(InfoText,"setText",Q_ARG(QVariant,"你的系统为："+SystemCheck::SInfo.SysName+" "+QString::number(SystemCheck::SInfo.SysBit)+a));
    if (SystemCheck::CheckCPU())
        qDebug() << "CPU: "<<SystemCheck::SInfo.cpu_Info;

    if (SystemCheck::CheckGPU())
        //qDebug() << "GPU_Driver: "<<SystemCheck::SInfo.GCardDriverVer;
        //qDebug() << "Check_GPU_Driver";
        QMetaObject::invokeMethod(InfoText,"setText",Q_ARG(QVariant,"你的显卡为："+SystemCheck::SInfo.GCardDriverVer));

    return app.exec();
}
